using System;
using System.Text;
using Portal.Core;
using Portal.Data.Entity;
using Portal.Data.Webparts;
using Portal.Data.Config;

public partial class Webparts_Misc_RssList : WebpartControl
{
    public string PortalName;

    public override WebpartConfig NewConfig
    {
        get { return new ListRssConfig(); }
    }

    public ListRssConfig PartConfig
    {
        get { return (ListRssConfig)Config; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {        
        if (Request["rss"] != null)
            return;
      
        var sb = new StringBuilder();
        if (!string.IsNullOrEmpty(PartConfig.Categories))
        {
            sb.Append("<table>");
            string[] listCategorySelected = PartConfig.Categories.Split(',');
            foreach (string t in listCategorySelected)
            {
                Category cat = Category.FindByPrimaryKey(t);
                if (cat != null)
                {
                    string rssUrl = string.Format("{0}rss/{1}/", CoreContext.basepath, cat.Name);
                    sb.Append("<tr>");

                    sb.Append("<td><a href=\"");
                    sb.Append(rssUrl);
                    sb.Append("\"><img border='0' src=\"Themes/Images/rss.gif\"></a></td>");

//                    sb.Append("<td><a href=\"http://add.my.yahoo.com/rss?url=");
//                    sb.Append(rssUrl);
//                    sb.Append("\"><img border='0' src=\"Themes/Images/AddYahoo.gif\"></a></td>");

                    sb.Append("<td><a class=RSSName href=\"");
                    sb.Append(rssUrl);
                    sb.Append("\">");
                    sb.Append(cat.FullName);
                    sb.Append("</a></td>");

                    sb.Append("<td> (<a class=RSSLink href=\"");
                    sb.Append(rssUrl);
                    sb.Append("\">");
                    sb.Append(rssUrl);
                    sb.Append("</a>)</td>");

                    sb.Append("</tr>");
                }
            }
            sb.Append("</table>");
        }

        ltrListRss.Text = sb.ToString();
    }
}